#pragma once
#ifndef __ROUTERSERVER_H__
#define __ROUTERSERVER_H__

#include <msg/message.h>
#include <net/tcp_server.hpp>
#include <util/ClientTable.h>
#include <util/Endpoint.hpp>
#include <util/Epoll.hpp>
#include <util/thread_pool.hpp>



class RouterServer{
public:
    RouterServer(uint16_t server_port);

    void start();

private:
    void accept_client();

    void hand_request(int fd, message msg);

    void hand_forward(message msg);

    static void read_from_fd(RouterServer* router, epoll_data_t data);

public:
    static Endpoint const SERVER_ENDPOINT;

private:
    Epoll ep;
    tcp_server server;
    ThreadPool thread_pool;
    ClientTable client_table;
};

inline Endpoint const RouterServer::SERVER_ENDPOINT = {1, 1, 0};
#endif // __ROUTERSERVER_H__